package com.dbh.company;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        String pointArrStr = "117.003417,36.65052;117.020507,36.670156;116.997875,36.667151;116.960453,36.676633;" +
                "116.973735,36.690639;120.38262,36.06713;117.017194,36.638034;120.315709,36.066718;120.42923,36.073756;" +
                "120.17564,35.96924;117.003417,36.65052;117.125843,36.648687;117.120128,36.652069";

        // 解析坐标字符串，按分号分割
        String[] points = pointArrStr.split(";");
        
        // 统计每个坐标出现的次数
        Map<String, Integer> pointCountMap = new LinkedHashMap<>();
        List<Integer> pointPositions = new ArrayList<>();
        
        for (int i = 0; i < points.length; i++) {
            String point = points[i].trim();
            if (!point.isEmpty()) {
                // 统计出现次数
                pointCountMap.put(point, pointCountMap.getOrDefault(point, 0) + 1);
                // 记录每个坐标在原数组中的位置
                pointPositions.add(i);
            }
        }
        
        System.out.println("总共坐标点数量: " + points.length);
        System.out.println("去重后坐标点数量: " + pointCountMap.size());
        System.out.println();
        
        // 找出重复的坐标
        System.out.println("=== 重复的经纬度 ===");
        boolean hasDuplicate = false;
        for (Map.Entry<String, Integer> entry : pointCountMap.entrySet()) {
            if (entry.getValue() > 1) {
                hasDuplicate = true;
                System.out.println("坐标: " + entry.getKey() + " 出现次数: " + entry.getValue() + " 次");
                
                // 显示该坐标出现的位置
                System.out.print("  位置索引: ");
                List<Integer> positions = new ArrayList<>();
                for (int i = 0; i < points.length; i++) {
                    if (points[i].trim().equals(entry.getKey())) {
                        positions.add(i);
                    }
                }
                System.out.println(positions);
            }
        }
        
        if (!hasDuplicate) {
            System.out.println("未发现重复的经纬度");
        }
        
        System.out.println();
        System.out.println("=== 所有坐标统计 ===");
        for (Map.Entry<String, Integer> entry : pointCountMap.entrySet()) {
            System.out.println("坐标: " + entry.getKey() + " -> 出现 " + entry.getValue() + " 次");
        }
    }
}
